import os
import sys
import time
import unittest
from HTMLTestRunner import HTMLTestRunner
#suite=unittest.TestSuite()
# 使用addTest
# suite.addTest(Test1.testCase1("test_baidu1"))
# suite.addTest(Test1.testCase1("test_baidu2"))
# suite.addTest(Test2.testCase2("test_baidu1"))
# suite.addTest(Test2.testCase2("test_baidu2"))


#使用makesuite
#suite.addTest(unittest.makeSuite(Test1.testCase1))
#suite.addTest(unittest.makeSuite(Test2.testCase2))


#使用testLoader
suite = unittest.TestLoader().discover("./","Test*.py")

#runner = unittest.TextTestRunner()
#runner.run(suite)


# 获取当前文件所在的文件路径
curpath = sys.path[0]
print(curpath)
if not os.path.exists(curpath+"/resultReport"):
    os.makedirs(curpath+"/resultReport")
now = time.strftime("%Y-%m-%d-%H %M %S",time.localtime(time.time()))
filename=curpath+"/resultReport/"+now+"-"+"resultReport.html"
with open(filename,"wb") as fp:
    runner = HTMLTestRunner(stream=fp,title=u"测试报告")
    runner.run(suite)


